package com.example.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.article.dao.ApAuthorDao;
import com.example.article.service.ApAuthorService;
import com.usian.model.article.dtos.ApAuthorDto;
import com.usian.model.article.pojos.ApAuthor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ApAuthorServiceImpl implements ApAuthorService {
    @Autowired
    private ApAuthorDao apAuthorDao;
    @Override
    public Integer addApAuthor(ApAuthorDto apAuthorDto) {
        ApAuthor apAuthor = new ApAuthor();
        apAuthor.setType(2);
        apAuthor.setCreatedTime(new Date());
        BeanUtils.copyProperties(apAuthorDto,apAuthor);
        return apAuthorDao.insert(apAuthor);
    }

    @Override
    public List<ApAuthor> getAuthorByName(String name) {
        LambdaQueryWrapper<ApAuthor> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ApAuthor::getName,name);
        return apAuthorDao.selectList(lambdaQueryWrapper);
    }
}
